/*
 * Copyright (C) 2012 Le Tuan Anh <anh.takaji@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package ezcms.ejb;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageListener;

/**
 *
 * @author Le Tuan Anh <anh.takaji@gmail.com>
 */
@MessageDriven(mappedName = "jms/ezcms.queue.mail.notifier", activationConfig = {
    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
})
public class MailPushBean implements MessageListener {

    public MailPushBean() {
    }

    @Override
    public void onMessage(Message message) {
        if (message != null && message instanceof MapMessage) {
            MapMessage mm = (MapMessage) message;
            try {
                System.out.println("Title:" + mm.getString("Title") + " - Body:" + mm.getString("Body"));
            } catch (JMSException ex) {
                Logger.getLogger(MailPushBean.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}
